package com.taotao.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.ExceptionUtil;
import com.taotao.pojo.TbContent;
import com.taotao.service.ContentService;

@Controller
@RequestMapping("/content")
public class ContentController {
	@Autowired
	private ContentService contentService;
	
	@RequestMapping("/query/list")
	@ResponseBody
	public EUDataGridResult getListByContentCategoryId(Long categoryId,int page,int rows){
		EUDataGridResult listByContentCategoryId = contentService.getListByContentCategoryId(categoryId, page, rows);
		return listByContentCategoryId;
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public TaotaoResult saveContent(TbContent content) throws Exception {
		TaotaoResult result = contentService.saveContent(content);
		return result;
	}
	
	
	@RequestMapping("/edit")
	@ResponseBody
	public TaotaoResult updateContent(TbContent content) throws Exception {
		TaotaoResult result = contentService.updateContent(content);
		return result;
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public TaotaoResult removeContent(Long  ids) {
		TaotaoResult result;
		try {
			result = contentService.removeContent(ids);
		} catch (Exception e) {
			String stackTrace = ExceptionUtil.getStackTrace(e);
			e.printStackTrace();
			return TaotaoResult.build(500, "", stackTrace);
		}
		return result;
	}
	
}
